import java.util.HashMap;
import java.util.Map;

public class LeetCode1044 {
    public static void main(String[] args) {

    }

    public static String longestDupSubstring(String s) {

        int maxLength = -1;
        String maxCountStr = "";

        for (int i = 0; i < s.length(); i++) {
            for (int j = i + 1; j <= s.length(); j++) {
                String s1 = s.substring(i, j);
                if (j - i <= maxLength) {
                    continue;
                }

                if (s.indexOf(s1) != s.lastIndexOf(s1) && s1.length() > maxLength) {
                    maxCountStr = s1;
                    maxLength = s1.length();
                }
            }
        }

        return maxCountStr;

    }
}
